home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 5.2 KB | 165 lines | [TEXT/GEOL] |
- Item 2530142 1-Feb-91 05:34PST
-
- From: POWERUP.ENG Power Up Software,PRT
-
- To: MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: TESetText()
-
- Attn: MacApp.Tech$
- SentBy: James Plamondon
- Subject: TESetText()
- Gentlepersons,
-
- I am having some trouble with a routine that uses TESetText(). For some
- inexplicable reason, it crashes somewhere in the bowels of _TextBox(), which I
- gather is called by TESetText().
-
- The purpose of the routine is to determine the height of the given styled
- string in the given column width.
-
- This one's got me stumped. I'd appreciate any advice you can give me. I know
- that you don't have much to go on.
-
- Looking forward to discovering that I've made a really stupid (and easily
- corrected) mistake, I remain
-
- Yours,
-
- James Plamondon
-
-
-
- {——————————————————————————————————————————————————————————————————————————————
- }
- {$ AUtil}
-
- { TextHeightInCol(): This routine determines how tall a given string will
- be, when displayed in a given style, with a given wordbreak routine, and
- in a column of given width and infinite (well, maxint) height. }
- FUNCTION TextHeightInCol(
- itsText: Ptr;
- itsLength: LONGINT;
- itsWidth: INTEGER;
- itsTextStyle: TextStyle;
- itsWordBreak: ProcPtr)
- : INTEGER;
- CONST
- kMaxTEChars = 32000;
- kMinColWidth = 20;
-
- VAR
- result: INTEGER;
- theFontInfo: FontInfo;
-
- BEGIN
- {$IFC qDebug}
- FailNil(gZZZZZTE); { Initialized
- in InitUProtoUtilities() }
-
- UseZZZZZTE(TRUE);
- {$ENDC qDebug}
-
- IF (itsLength = 0) | (itsWidth <= kMinColWidth) | (itsText = NIL)
- THEN
- result := 0
- ELSE
- BEGIN
- GetTextStyleFontInfo(itsTextStyle, theFontInfo);
-
- IF (itsWidth < theFontInfo.widMax)
- THEN
- result := 0
- ELSE
- BEGIN
- WITH gZZZZZTE^^ DO
- BEGIN
- SetRect(destRect, 0, 0, itsWidth, maxint);
- SetRect(viewRect, 0, 0, itsWidth, maxint);
-
- inPort := thePort; { Current port
- }
-
- {$IFC qDebug}
- Assertion((crOnly = 0), AtStr('(crOnly = 0)')); { if >=0, word
- wrap }
- {$ENDC qDebug}
-
- wordBreak := gTEDefaultWordBreak;
- END; { with }
-
- IF itsWordBreak <> NIL
- THEN
- SetWordBreak(itsWordBreak, gZZZZZTE); { set the word
- break routine }
-
-
- {————————————————————————————————————————————————————————————————
- NOTE!!! before writing your wordBreak routine, be sure to read
- Tech Note 267, "TextEdit Technicalities."
-
- ————————————————————————————————————————————————————————————————}
-
- {$IFC qDebug}
- (*
- writeln;
- writeln('In TextHeightInCol(), about to call TESetText():');
- write (' itsText = ');
- WriteHexLongint(LONGINT(itsText)); writeln;
- writeln(' itsLength = ', Min(itsLength,
- kMaxTEChars):1);
- writeln(' itsWidth = ', itsWidth:1);
- writeln(' theFontInfo.widMax = ', theFontInfo.widMax:1);
- write (' gZZZZZTE^^.destRect = ');
- WriteRect(gZZZZZTE^^.destRect); writeln;
- write (' gZZZZZTE = ');
- WriteHexLongint(LONGINT(gZZZZZTE)); writeln;
- write (' gZZZZZTE^ = ');
- WriteHexLongint(LONGINT(gZZZZZTE^)); writeln;
- write (' itsWordBreak = ');
- WriteHexLongint(LONGINT(itsWordBreak)); writeln;
- write (' gZZZZZTE^^.wordBreak = ');
- WriteHexLongint(LONGINT(gZZZZZTE^^.wordBreak)); writeln;
- *)
- {$ENDC qDebug}
-
- { The code dies in the bowels of the following call. Why? I haven't a
- clue! }
- TESetText(itsText, Min(itsLength, kMaxTEChars), gZZZZZTE);
-
- { set the text style }
- TESetSelect(0, maxint, gZZZZZTE); { select all of
- the text }
- TESetStyle(doAll, itsTextStyle, kDontRedraw, gZZZZZTE); { set its
- style (!!! compatibility???) }
- TECalText(gZZZZZTE); {
- ???necessary??? }
-
- result := TEGetHeight(
- gZZZZZTE^^.nLines, { end line }
- 0, { start line }
- gZZZZZTE); { the TEHandle
- }
-
- {$IFC qDebug}
- (*
- writeln;
- writeln('In TextHeightInCol():');
- writeln(' itsWidth = ', itsWidth:5);
- writeln(' gZZZZZTE^^.nLines = ', gZZZZZTE^^.nLines:5);
- writeln(' result = ', result:5);
- *)
- {$ENDC qDebug}
- END; { else }
- END; { else }
-
- TextHeightInCol := result;
-
- {$IFC qDebug}
- UseZZZZZTE(FALSE);
- {$ENDC qDebug}
- END; { TextHeightInCol }
-
-